getDBGroup <- function(groupcode, latex=FALSE, OOS=FALSE) {
  searchGroupSQL <- function(groupcode) {
    sql <- sprintf ("SELECT `id`, `name` FROM `groupname` WHERE `code` ='%s'", groupcode)
    return (sql)
  }
  searchSymbolsSQL <- function(id) {
    sql <- sprintf ("SELECT `stock_id`, `code`, `name`, `from`, `to` 
                    FROM `groupmap` JOIN `stockname` ON (groupmap.stock_id=stockname.id) 
                    WHERE `group_id`= %s ORDER BY `code`", id)
    return (sql)
  }
  
  con <- connectToVadb()
  
  # load xtable
  if (latex==TRUE) {
    if('package:xtable' %in% search() || require('xtable',quietly=TRUE)) {}
  }
  symbols<-data.frame()
  for(thisgc in groupcode) {
    groupname <- dbGetQuery(con, searchGroupSQL(thisgc))  
    if (dim(groupname)[1]==0) {
      dbDisconnect(con)
      stop("Group does not exist")
    }
    
    if (nrow(symbols)==0) {
      symbols <- dbGetQuery(con, searchSymbolsSQL(groupname['id']))      
    } else {
      symbols <- rbind(symbols, dbGetQuery(con, searchSymbolsSQL(groupname['id'])))
    }    
  }
  
  if (OOS==TRUE) {
    groupnameOOS <- dbGetQuery(con, searchGroupSQL(paste(groupcode, "_OOS", sep="") ))
    symbolsOOS <- dbGetQuery(con, searchSymbolsSQL(groupnameOOS['id']))
    if (dim(groupnameOOS)[1]==0) {
      dbDisconnect(con)
      stop("Out of Sample Group does not exist")
    }
  }
  
  dbDisconnect(con)
  
  if (latex==FALSE) {
    return (symbols) # symbols is returned as data.frame
  } else {
    mydf <- symbols[2:5]
    caption="Zusammensetzung des Test- Datensatz ''xxx''"
    label=paste("tab", groupcode, sep=":")
    if (OOS==TRUE) {
      mydf <- cbind(mydf, symbolsOOS[4:5])
      colnames(mydf) <- c("Symbol", "Name", "von", "bis", "von", "bis")
      xt <- xtable(mydf,
                   caption=caption,
                   label=label,
                   display=c("s","s","s","s","s","s","s"),
                   align="|rll|cc|cc|")
      return(xt)
    } else {
      colnames(mydf) <- c("Symbol", "Name", "von", "bis")
      xt <- xtable(mydf,
                   caption=caption,
                   label=label,
                   display=c("s","s","s","s","s"),
                   align="|rll|cc|")
      return(xt)
    }
  }
}